#include  "ros/ros.h"
#include "turtlesim/Spawn.h"

/**
 * 需求：生成1只小乌龟
 * 使用spawn=服务
 * 1， 添加头文件
 * 2， 初始化节点
 * 3， 创建句柄
 * 4， 创建客户端
 * 5， 组织数据并发送
 * */

int main(int argc, char** argv)
{
    setlocale(LC_ALL, "");

    ros::init(argc, argv, "spawn_client");

    ros::NodeHandle nh;

    ros::ServiceClient client=nh.serviceClient<turtlesim::Spawn>("/spawn");

    turtlesim::Spawn spawn;
    spawn.request.x=1.0;
    spawn.request.y=4.0;
    spawn.request.theta=1.57;
    spawn.request.name="turtle2";

    client.waitForExistence();
    bool flag=client.call(spawn);
    
    if(flag){
        ROS_INFO("乌龟生成成功， 新乌龟叫 ： %s", spawn.response.name.c_str());
        }else{
        ROS_INFO("生成失败");
    }
    
    return 0;
}
